package com.example.teacherservice.repository;

import com.example.teacherservice.entity.TeaClass;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TeaClassRepository extends JpaRepository<TeaClass, Long> {

    // 简单查询（返回列表）
    List<TeaClass> findByTeaId(Long teaId);

    // 基础分页查询
    Page<TeaClass> findByTeaId(Long teaId, Pageable pageable);

    // 带名称筛选的分页查询（模糊查询）
    Page<TeaClass> findByTeaIdAndClassNameContaining(Long teaId, String className, Pageable pageable);

    // 可选：添加删除方法
    void deleteByTeaIdAndClassId(Long teaId, Long classId);


    List<TeaClass> findByClassId(Long classId);

    boolean existsByTeaIdAndClassId(Long teaId, Long classId);


    @Modifying
    @Query("DELETE FROM TeaClass tc WHERE tc.classId = :classId")
    void deleteByClassId(@Param("classId") Long classId);

}